package com.infolab.aims.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.validator.constraints.NotBlank;

import com.infolab.aims.common.SpecialToStringStyle;
import com.infolab.aims.common.bean.AbstractModelBean;


@Entity
@Table(name="AMTB_SECTION")
public class Section extends AbstractModelBean implements Serializable {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer sectionId;
	
	@NotBlank(message="{error.empty}")
	private String sectionCode;
	
	@NotBlank(message="{error.empty}")
	private String sectionName;
	
	@Column(columnDefinition="number(1,0) default 1 not null")
	private boolean active;

	@ManyToOne
	@JoinColumn(name="departmentId")
	@NotNull(message="{error.empty}")
	private Department department;

	public Integer getSectionId() {
		return sectionId;
	}

	public void setSectionId(Integer sectionId) {
		this.sectionId = sectionId;
	}

	public String getSectionCode() {
		return sectionCode;
	}

	public void setSectionCode(String sectionCode) {
		this.sectionCode = sectionCode;
	}

	public String getSectionName() {
		return sectionName;
	}

	public void setSectionName(String sectionName) {
		this.sectionName = sectionName;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}
	
	public String getAuditContentHead()
	{
		
		Department dept = department!=null? department:new Department();
		
		return new ToStringBuilder(this,SpecialToStringStyle.SPECIAL_STYLE)
			.append("Section Code ",sectionCode)
			.append("Section Name ",sectionName)
			.append("Department",dept.getDepartmentName()!=null?dept.getDepartmentName():"Yet to Update")
			.toString();
	}
	
	public String getAuditContentDetail()
	{		
		return super.getAuditContentDetail();
	}
	
	public String getAuditCode()
	{
		if(StringUtils.isNotEmpty(sectionCode)){
			return sectionCode;
		}
		return super.getAuditCode();
	}
}
